package homework;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @classname:demo05
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/9 23:02
 * @version: 0.1
 * @since:1.8
 */
public class demo05 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入第一个时间yyyy-MM-dd HH-mm-ss");
        String str1 = input.nextLine();
        System.out.println("请输入第二个时间yyyy-MM-dd HH-mm-ss");
        String str2 = input.nextLine();
        System.out.println("两个时间相差"+disHour(str1, str2)+"小时");

    }

    private static int disHour(String str1,String str2) {
        String pattern = "yyyy-MM-dd HH-mm-ss";
        DateFormat dateFormat = new SimpleDateFormat(pattern);
        int retuentime  = 0;
        try {
            Date parse = dateFormat.parse(str1);
            Date parse1 = dateFormat.parse(str2);
            long distimesecen = parse1.getTime()-parse.getTime();
            int disTinehour = (int)distimesecen/1000/3600;
            int time = Math.abs(disTinehour);
            retuentime = time;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return retuentime;
    }
}
